<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
	{include="style"}
	{include="edit"}
  </head>
  
  <body>
    <div class="x-body">
        <form class="layui-form layui-form-pane">
		
		<div class="layui-tab">
			  <ul class="layui-tab-title">
				<li class="layui-this">基本信息</li>
				<li>扩展信息</li>
				
			  </ul>
			  <div class="layui-tab-content">
				<div class="layui-tab-item layui-show">
				<div class="layui-form-item">
			<label for="molds" class="layui-form-label">
				<span class="x-red">*</span>选择模块
			</label>
			<div class="layui-input-inline">
				<select name="molds" id="molds" lay-filter="molds" >
			   
			   {foreach $molds as $v}
			   {if($v['biaoshi']!='classtype' && $v['isshowclass']==1)}
			   <option {if($biaoshi==$v['biaoshi'])} selected="selected" {/if}  value="{$v['biaoshi']}">{$v['name']}</option>
			   {/if}
			   {/foreach}
			
			   </select>
			</div>
        </div>
		<div class="layui-form-item">
			<label for="pid" class="layui-form-label">
				<span class="x-red">*</span>选择上级
			</label>
			<div class="layui-input-inline">
				<select name="pid" lay-search="" id="pid"  lay-filter="pid">
			   <option value="0">顶级栏目</option>
			   {foreach $classtypes as $v}
			   {if($admin['classcontrol']==0 || $admin['isadmin']==1 || strpos($tids,','.$v['id'].',')!==false || $molds['iscontrol']==0)}
			   <option {if($pid==$v['id'])}selected{/if}  value="{$v['id']}">{fun str_repeat('--', $v['level'])}{$v['classname']}</option>
			   {/if}
			   {/foreach}
			
			   </select>
			</div>
        </div>
          <div class="layui-form-item">
              <label for="classname" class="layui-form-label">
                  <span class="x-red">*</span>分类名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="classname" name="classname" required="" lay-verify="required"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  
              </div>
          </div>
		  <div class="layui-form-item">
              <label for="seo_classname" class="layui-form-label">
                  <span class="x-red"></span>SEO标题
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="seo_classname" name="seo_classname" 
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  
              </div>
          </div>
		  <div class="layui-form-item">
              <label for="keywords" class="layui-form-label">
                  <span class="x-red"></span>关键词
              </label>
              <div  style="width:500px"  class="layui-input-inline">
                  <input type="text" id="keywords" name="keywords" 
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  
              </div>
          </div>
		  
			
			<div class="layui-form-item">
				<label for="litpic" class="layui-form-label">
					<span class="x-red"></span>图片  
				</label>
				
				<div class="layui-input-inline">
					<input name="litpic" placeholder="上传图片" type="text" class="layui-input" id="litpic"  value="" />
				</div>
				<div class="layui-input-inline">
					<button class="layui-btn layui-btn-primary" id="litpic_upload" type="button" >选择图片</button>
				</div>
				<div class="layui-input-inline">
					<img id="litpic_img" class="img-responsive img-thumbnail" style="max-width: 200px;" src="" onerror="javascipt:this.src='{__Tpl_style__}/style/images/nopic.jpg'; this.title='图片未找到';this.onerror=''">
					<button type="button" onclick="deleteImage(this)" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-danger " title="删除这张图片" >删除</button>
				</div>
			</div>
	
				<div class="layui-form-item layui-form-text">
                        <label for="description" class="layui-form-label">
                            <span class="x-red"></span>简介
                        </label>
                        <div class="layui-input-block">
                            <textarea  name="description" class="layui-textarea"></textarea>
                        </div>
                    </div>
				 <div class="layui-form-item layui-form-text">
                    <label for="body" class="layui-form-label">
                        <span class="x-red"></span>内容
                    </label>
                    <div class="layui-input-block" style="clear:both;" >
					   {include="content"}
                    </div>
                </div>
				 
				{if($webconf['isrelative']==1)}
				<span id="ext_fields"></span>
				{/if}
		 
			
				</div>
				<div class="layui-tab-item">
				
				{if($webconf['isrelative']==0)}
				<span id="ext_fields"></span>
				{/if}
				
				 <div class="layui-form-item">
					  <label for="orders" class="layui-form-label">
						  <span class="x-red"></span>排序
					  </label>
					  <div class="layui-input-inline">
						  <input type="number" id="orders" name="orders" value="0" 
						  autocomplete="off" class="layui-input">
					  </div>
					  <div class="layui-form-mid layui-word-aux">
						  <span class="x-red"></span>
					  </div>
				  </div>
				   <div class="layui-form-item">
					  <label for="orderstype" class="layui-form-label">
						  <span class="x-red"></span>排序规则
					  </label>
					  <div class="layui-input-inline">
						  <select name="orderstype" id="orderstype">
						  <option value="1">1 排序倒序，2 时间倒序，3 ID倒序</option>
						  <option value="2">1 排序倒序，2 ID正序</option>
						  <option value="3">排序正序</option>
						  <option value="4">时间倒序</option>
						  <option value="5">ID正序</option>
						  <option value="6">热度倒序</option>
						  <option value="7">时间正序</option>
						  </select>
					  </div>
					  <div class="layui-form-mid layui-word-aux">
						  <span class="x-red">默认不需要更改</span>
					  </div>
				  </div>
		   <div class="layui-form-item">
              <label for="htmlurl" class="layui-form-label">
                  <span class="x-red"></span>URL命名
              </label>
              <div class="layui-input-block">
                  <input type="text" placeholder="请填写文件名，如:index，不填请留空" style="width:350px"  id="htmlurl" name="htmlurl" value="" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                填写栏目命名后，系统将自动用作该栏目URL链接，如：news，访问该栏目链接：{fun get_domain()}/news.html。多个相同URL，将覆盖前面的栏目
              </div>
          </div>
		  <div class="layui-form-item">
              <label for="lists_num" class="layui-form-label">
                  <span class="x-red"></span>列表显示
              </label>
              <div class="layui-input-inline">
                  <input type="number" id="lists_num" name="lists_num" value="10" 
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  设置列表页显示的内容条数
              </div>
          </div>
		  <div class="layui-form-item">
              <label for="lists_html" class="layui-form-label">
                  <span class="x-red"></span>栏目模板
              </label>
              <div  style="width:350px"  class="layui-input-inline">
              	<select name="lists_html" lay-search="" id="lists_html"  >
				
              	</select>
                  
              </div>
			  <div class="layui-input-inline">
                  <input type="text" id="lists_html_write" name="lists_html_write" placeholder="手动填写，不填请留空" value="" 
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                 请将模板文件放到对应的模块文件夹下面，如文章(article)模块，那么就要在当前模板目录的article文件夹下面。默认栏目首页
              </div>
          </div>
		  <div class="layui-form-item">
              <label for="details_html" class="layui-form-label">
                  <span class="x-red"></span>详情页模板
              </label>
              <div  style="width:350px"  class="layui-input-inline">
              	<select name="details_html" lay-search="" id="details_html"  >
              	</select>
                
              </div>
			  <div class="layui-input-inline">
                  <input type="text" id="details_html_write" name="details_html_write" placeholder="手动填写，不填请留空" value="" 
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                 请将模板文件放到对应的模块文件夹下面，如文章(article)模块，那么就要在当前模板目录的article文件夹下面，列表内的详情页。
              </div>
          </div>
		   <div class="layui-form-item">
              <label for="gourl" class="layui-form-label">
                  <span class="x-red"></span>栏目外链
              </label>
              <div class="layui-input-block">
                  <input type="text" placeholder="栏目外链，如:htt://xxx.com/abc，不填请留空" style="width:350px"  id="gourl" name="gourl" value="" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
               填写栏目外链后，访问栏目链接将会跳到外链，不填请留空！
              </div>
          </div>
		   <div class="layui-form-item" pane>
					<label for="ishome" class="layui-form-label">
						<span class="x-red"></span>发布显示
					</label>
					<div class="layui-input-block">
						<input type="radio" name="ishome" value="0" title="不显示" >
						<input type="radio" name="ishome" value="1" title="显示" checked>
					</div>
					<div class="layui-form-mid layui-word-aux">
					 勾选后，前台会员发布会显示该栏目
					</div>
					
			  </div>
		  <div class="layui-form-item" pane>
                    <label for="isshow" class="layui-form-label">
                        <span class="x-red"></span>导航显示
                    </label>
                    <div class="layui-input-inline">
                        <input type="radio" name="isshow" value="0" title="隐藏">
						<input type="radio" name="isshow" value="1" title="显示" checked>
                    </div>
			</div>
			<div class="layui-form-item" pane>
				<label for="iscover" class="layui-form-label">
					<span class="x-red"></span>模板覆盖
				</label>
				<div class="layui-input-block">
					<input type="radio" name="iscover" value="1" title="覆盖">
					<input type="radio" name="iscover" value="0" title="不覆盖" checked >
				</div>
				<div class="layui-form-mid layui-word-aux">
                 模板覆盖指：显示数量及使用模板文件下级一样，减少同步操作。如果上级勾选了覆盖下级，那么下级默认调用上级填写的模板。
                </div>
				
			</div>
			
			<div class="layui-form-item">
				<label for="gid" class="layui-form-label">
					<span class="x-red"></span>访问限制
				</label>
				<div class="layui-input-inline">
					<select name="gid" id="gid" >
				    <option value="0">不限</option>
				   
				   {loop table="member_group" as="v"}
				  
				   <option   value="{$v['id']}">{$v['name']}</option>
				   
				   {/loop}
				
				   </select>
				</div>
			</div>
				
			 <div class="layui-form-item" pane>
                    <label for="isclose" class="layui-form-label">
                        <span class="x-red"></span>是否关闭
                    </label>
                    <div class="layui-input-inline">
                        <input type="radio" name="isclose" value="1" title="关闭">
						<input type="radio" name="isclose" value="0" title="开启" checked>
                    </div>
					<div class="layui-form-mid layui-word-aux">
					 栏目关闭后，前台不显示，也无法访问！
					</div>
			</div>	
				
				</div>
			  </div>
		</div>
				
		
		
		
          <input type="hidden" id="go" name="go" value="1">
          <div class="layui-form-item" style="text-align:center;">
              
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  增加
              </button>
          </div>
      </form>
    </div>
    <script>
	{include="fields"}
		
		function deleteImage(elm){
			$(elm).prev().attr("src", "{__Tpl_style__}/style/images/nopic.jpg");
			$('#litpic').val("");
		}
        layui.use(['form','layer','upload'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
          var upload = layui.upload;
         
		  upload.render({
			elem: '#litpic_upload',
			url: "{fun U('Common/uploads')}" //上传接口
			,done: function(res){ //上传成功后的回调
			 
				if(res.code==0){
					 $('#litpic_img').attr('src',res.url);
					 $('#litpic').val(res.url);
				}else{
					 layer.alert(res.error, {icon: 5});
				}
			 
			}
		  });


          //监听提交
          form.on('submit(add)', function(data){
            
					$.post('{fun U('Classtype/addclass')}',data.field,function(r){
					
					
						r = JSON.parse(r);

						if(r.status==0){
							layer.msg(r.info, {
							  icon:5
							});
						}else{
						
							layer.confirm(r.info, {
							  btn: ['返回','确定'] //按钮
							}, function(){
							  
							   
							   {if($webconf['admintpl']=='tpl')}
							   window.location.href="{fun U('Classtype/index')}";
							  {else}
							   parent.location.reload();
							   parent.layer.close(index);
							  {/if}
							   
							   
							}, function(){
							   window.location.href=r.url;
							});
							
						
						}
					});
                return false;
          });
		 
		   get_fields({$pid});
		   form.on('select(pid)', function(data){
			  
			  get_fields(data.value);
			  
			  
			});
		   form.on('select(molds)', function(data){
			  
			 get_molds_html($("#molds").val());
			 form.render('select');
			  
			});
			
           $("#classname").blur(function(){
				var classname = $("#classname").val();
				
				$.post("{fun U('get_pinyin')}",{'classname':classname},function(r){
					var res = JSON.parse(r);
					if(res.code==0){
						$("#htmlurl").val(res.data);
					}
				
				})
			
			
			});
          
        });

        function get_molds_html(molds){
        	$.ajax({
				 url:"{fun U('Classtype/get_html')}",//请求的url地址
				 dataType:"json",//返回格式为json
				 async:false,
				 data:{molds:molds},//参数值
				 type:"POST",//请求方式
				 beforeSend:function(){
					//请求前的处理
					},
				 success:function(r){
					 	var t = '<option value="">请选择模板页面/使用自定义</option>';var tt = '<option value="">请选择模板页面/使用自定义</option>';
						if(r.code==0){
							var len = r.data.length;
							if(len>0){
								var lists_html = r['lists_html'];
								var details_html = r['details_html'];
								for(var i=0;i<len;i++){
									var isok = 0;
									if(lists_html==r.data[i].value){
										t+='<option value="'+r.data[i].value+'" selected>'+r.data[i].html+'</option>';
										isok = 1;
									}else{
										t+='<option value="'+r.data[i].value+'">'+r.data[i].html+'</option>';
									}
									
									
								}
								
								for(var i=0;i<len;i++){
									var isok = 0;
									if(details_html==r.data[i].value){
										tt+='<option value="'+r.data[i].value+'" selected>'+r.data[i].html+'</option>';
										isok = 1;
									}else{
										tt+='<option value="'+r.data[i].value+'">'+r.data[i].html+'</option>';
									}
									
									
								}
								
									
								
							}

						}else{
							alert(r.msg);
						}
						$("#lists_html").html(t);
						$("#details_html").html(tt);
					},
					 complete:function(){
					//请求完成的处理
					},
					 error:function(){
					//请求出错处理
					}

			})
        	}


        $(document).ready(function(){

        	
        	get_molds_html($("#molds").val());
        })

    </script>
    
  </body>

</html>